/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package merlion.common.entity;

import java.io.Serializable;
import java.sql.Timestamp;
import java.text.SimpleDateFormat;
import java.util.ArrayList;
import java.util.Collection;
import javax.persistence.CascadeType;
import javax.persistence.Entity;
import javax.persistence.FetchType;
import javax.persistence.GeneratedValue;
import javax.persistence.GenerationType;
import javax.persistence.Id;
import javax.persistence.OneToMany;

/**
 *
 * @author Zhang Ying
 */
@Entity
public class Announcement implements Serializable {
    private static final long serialVersionUID = 1L;
    @Id
    @GeneratedValue(strategy = GenerationType.AUTO)
    private Long id;
    private String title;
    private Timestamp announceDate;
    private String content;
    private Long posterId;
    @OneToMany(targetEntity=SecurityRole.class,cascade={CascadeType.MERGE},fetch=FetchType.EAGER)
    private Collection<SecurityRole> audience = new ArrayList<SecurityRole>();
    
    public Announcement(){
        
    }
    
    public String getFormattedDate(){
        SimpleDateFormat sdf = new SimpleDateFormat("HH:mm:ss dd/MM/yyyy");
        return sdf.format(announceDate);
    }

    public Long getId() {
        return id;
    }

    public void setId(Long id) {
        this.id = id;
    }

    public Timestamp getAnnounceDate() {
        return announceDate;
    }

    public void setAnnounceDate(Timestamp announceDate) {
        this.announceDate = announceDate;
    }

    public Collection<SecurityRole> getAudience() {
        return audience;
    }

    public void setAudience(Collection<SecurityRole> audience) {
        this.audience = audience;
    }

    public String getContent() {
        return content;
    }

    public void setContent(String content) {
        this.content = content;
    }

    public Long getPosterId() {
        return posterId;
    }

    public void setPosterId(Long posterId) {
        this.posterId = posterId;
    }

    public String getTitle() {
        return title;
    }

    public void setTitle(String title) {
        this.title = title;
    }

    @Override
    public int hashCode() {
        int hash = 0;
        hash += (id != null ? id.hashCode() : 0);
        return hash;
    }

    @Override
    public boolean equals(Object object) {
        if (!(object instanceof Announcement)) {
            return false;
        }
        Announcement other = (Announcement) object;
        if ((this.id == null && other.id != null) || (this.id != null && !this.id.equals(other.id))) {
            return false;
        }
        return true;
    }

    @Override
    public String toString() {
        return "merlion.common.entity.Announcement[ id=" + id + " ]";
    }
    
}
